package com.yourcompany.struts.action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.dbOperation;

public class saleQuery extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String flag=request.getParameter("flag");
		String s=null;
		int pagenow=1;
		int pagesize=8;
		dbOperation db=new dbOperation();
		if(flag.equals("order")){
			if(request.getParameter("pagenow")!=null){
				pagenow=Integer.parseInt(request.getParameter("pagenow"));
				pagenow=pagenow==0?1:pagenow;
				}
			if(request.getParameter("str")!=null){
				s=request.getParameter("str");
			}else{
			String s1=request.getParameter("sordId");
			String s2=request.getParameter("maName");
			String s3=request.getParameter("departId");
			String s4=request.getParameter("sordDate");
			if(s1!=null&&!s1.equals("")){
				s1="and sordId='"+s1+"'";
				s2=s3=s4="";
			}else{
				if(s2!=null&&!s2.equals("")&&s3!=null&&!s3.equals("")&&s4!=null&&!s4.equals("")){
					return new ActionForward("/salOrdManage.do?flag=page");
				}else{
				if(s2!=null&&!s2.equals("")){
					s2="and maName='"+s2+"'";
				}
				if(s3!=null&&!s3.equals("")){
					s3="and departId='"+s3+"'";
				}
				if(s4!=null&&!s4.equals("")){
					s4="and sordDate='"+s4+"'";
				}
			  }
			}
				
			s=s1+s2+s3+s4;
			}
			ArrayList list=db.getSalOrder2(s, pagenow, pagesize);
			int pagecount = db.getSalOrderPagecount2(s);
			request.setAttribute("str", s);
			request.setAttribute("pagenow", pagenow+"");
			request.setAttribute("pagecount", pagecount+"");
			request.setAttribute("list", list);
			return mapping.findForward("salordquery");
		}
		return mapping.findForward("salordquery");
	}

}
